using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataAccessLayer;

public partial class AdminProfile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Session["type"]).ToString() != "admin")
            Response.Redirect("Error404.aspx");
    }
    protected void btnPopulate_Click(object sender, EventArgs e)
    {
        if (radioUser.Checked == true)
        {
            Session["toDelete"] = "user";
            Common c = new Common();
            string conn = c.fetchConnString();
            User rg = new User(conn);
            grdvwResults.DataSource = rg.Load();
            grdvwResults.DataBind();
        }
        else if (radioDoctor.Checked == true)
        {
            Session["toDelete"] = "doctor";
            Common c = new Common();
            string conn = c.fetchConnString();
            Doctor drg = new Doctor(conn);
            grdvwResults.DataSource = drg.Dloading();
            grdvwResults.DataBind();
        }

        if ((Session["toDelete"]).ToString() == "user")
        {
            lblPrimaryKey.Text = "Enter User Id :";
            btnDelete.Text = "Delete User";
        }
        else if ((Session["toDelete"]).ToString() == "doctor")
        {
            lblPrimaryKey.Text = "Enter Registration No. :";
            btnDelete.Text = "Delete Doctor";
        }
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if ((Session["toDelete"]).ToString() == "user")
        {
            Common c = new Common();
            string conn = c.fetchConnString();

            int userId = Convert.ToInt32(txtPrimaryKey.Text);
            Deletion dl = new Deletion(conn);
            dl.delUser(userId);
            User rg = new User(conn);
            grdvwResults.DataSource = rg.Load();
            grdvwResults.DataBind();
        }
        else if ((Session["toDelete"]).ToString() == "doctor")
        {
            Common c = new Common();
            string conn = c.fetchConnString();

            int regNo = Convert.ToInt32(txtPrimaryKey.Text);
            Deletion dl = new Deletion(conn);
            dl.delDoc(regNo);
            Doctor drg = new Doctor(conn);
            grdvwResults.DataSource = drg.Dloading();
            grdvwResults.DataBind();
        }
    }
    protected void btnModifyDisease_Click(object sender, EventArgs e)
    {
        Response.Redirect("ModifyDisease.aspx");
    }
    protected void btnModifyMedicine_Click(object sender, EventArgs e)
    {
        Response.Redirect("ModifyMedicine.aspx");
    }
}
